/* Common function */
var $id = function(id) {
	var node = document.getElementById(id); 
    return node ? node : document.getElementsByTagName(id)[0];
}

function createDiv() {
	return document.createElement("div");
}

function createTable(){
	var tb = createNode("table");
	tb.setAttribute("border","1");
	return tb;
}

function createTextNode(text){
	return document.createTextNode(text);
}

function createNode(type) {
	return document.createElement(type);
}

/* Implement Element object */
var _Ep = Element.prototype;

_Ep.hasClass = function(className) {
    return this.className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'));
}

_Ep.addClass = function(className) {
	return !this.hasClass(className) ? this.className += " " + className : this.className;
}

_Ep.removeClass = function(className) {
	if (this.hasClass(className)) {
        var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
        this.className = this.className.replace(reg,' ');
    }
}

_Ep.setId = function(name) {
	this.setAttribute("id", name);
}

_Ep.setText = function(text) {
	this.innerText = text; 
}
